package com.lmpop.trade.ti_advinfo;

import com.lmpop.frame.QueryList;
import com.lmpop.frame.SysMap;
import com.lmpop.frame.TradeInterf;
import com.lmpop.frame.dao.DbmInterf;
import com.lmpop.frame.exp.ApplicationException;
import java.util.Hashtable;
import java.util.List;

public class Ti_advinfoInfo implements TradeInterf
{
  QueryList queryList;

  public Ti_advinfoInfo()
  {
    this.queryList = new QueryList();
  }

  public SysMap insert(DbmInterf dbmMgr, SysMap map)
  {
    Ti_advinfo ti_advinfo = new Ti_advinfo();
    ti_advinfo.setAdv_id(map.getString("adv_id"));
    ti_advinfo.setCust_id(map.getString("cust_id"));
    ti_advinfo.setAdv_title(map.getString("adv_title"));
    ti_advinfo.setPos_id(map.getString("pos_id"));
    ti_advinfo.setAdv_src(map.getString("adv_src"));
    ti_advinfo.setAdv_text(map.getString("adv_text"));
    ti_advinfo.setStart_date(map.getString("start_date"));
    ti_advinfo.setEnd_date(map.getString("end_date"));
    ti_advinfo.setAdv_url(map.getString("adv_url"));
    ti_advinfo.setContact(map.getString("contact"));
    ti_advinfo.setContact_info(map.getString("contact_info"));
    ti_advinfo.setIn_date(map.getString("in_date"));
    ti_advinfo.setUser_id(map.getString("user_id"));
    ti_advinfo.setRemark(map.getString("remark"));

    String result_code = "0";
    try {
      insert(dbmMgr, ti_advinfo);
    } catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);
    return map;
  }

  public void insert(DbmInterf dbmMgr, Ti_advinfo ti_advinfo)
    throws ApplicationException
  {
    dbmMgr.update("insertTi_advinfo", ti_advinfo);
  }

  public SysMap delete(DbmInterf dbmMgr, SysMap map)
  {
    String pkid_string = map.getString("pkid");
    String result_code = "0";
    try {
      if (!pkid_string.equals("")) {
        String[] pkStr = pkid_string.split("\\|");
        for (int i = 0; i < pkStr.length; i++) {
          if (pkStr[i].equals("")) continue; delete(dbmMgr, pkStr[i]);
        }
      }
    } catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);

    map.setString("attach_root_id", pkid_string);
    map.setString("attach_sign", "delete");

    return map;
  }

  public void delete(DbmInterf dbmMgr, String pkid)
    throws ApplicationException
  {
    dbmMgr.update("deleteTi_advinfo", pkid);
  }

  public SysMap update(DbmInterf dbmMgr, SysMap map)
  {
    Ti_advinfo ti_advinfo = new Ti_advinfo();
    ti_advinfo.setAdv_id(map.getString("adv_id"));
    ti_advinfo.setCust_id(map.getString("cust_id"));
    ti_advinfo.setAdv_title(map.getString("adv_title"));
    ti_advinfo.setPos_id(map.getString("pos_id"));
    ti_advinfo.setAdv_src(map.getString("adv_src"));
    ti_advinfo.setAdv_text(map.getString("adv_text"));
    ti_advinfo.setStart_date(map.getString("start_date"));
    ti_advinfo.setEnd_date(map.getString("end_date"));
    ti_advinfo.setAdv_url(map.getString("adv_url"));
    ti_advinfo.setContact(map.getString("contact"));
    ti_advinfo.setContact_info(map.getString("contact_info"));
    ti_advinfo.setIn_date(map.getString("in_date"));
    ti_advinfo.setUser_id(map.getString("user_id"));
    ti_advinfo.setRemark(map.getString("remark"));

    String result_code = "0";
    try {
      update(dbmMgr, ti_advinfo);
    } catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);
    return map;
  }

  public void update(DbmInterf dbmMgr, Ti_advinfo ti_advinfo)
    throws ApplicationException
  {
    dbmMgr.update("updateTi_advinfo", ti_advinfo);
  }

  public List getListByPage(Object obj, int start, int limit)
  {
    Hashtable ti_advinfo = (Hashtable)obj;
    if (start == 0)
      start = 0;
    else {
      start = (start - 1) * limit;
    }
    ti_advinfo.put("start", Integer.valueOf(start));
    ti_advinfo.put("limit", Integer.valueOf(limit));
    return this.queryList.getList("getTi_advinfoList", ti_advinfo);
  }

  public int getCountByObj(Object obj)
  {
    Hashtable ti_advinfo = (Hashtable)obj;

    List list = this.queryList.getList("getTi_advinfoCount", ti_advinfo);
    int count = 0;
    if ((list != null) && (list.size() > 0)) {
      Hashtable newsMap = (Hashtable)list.get(0);
      if ((newsMap.get("count") != null) && (!newsMap.get("count").toString().equals(""))) {
        count = Integer.parseInt(newsMap.get("count").toString());
      }
    }
    return count;
  }

  public List getListByPk(String pk)
  {
    return this.queryList.getList("getTi_advinfoByPk", pk);
  }
}